package com.entrogy.bean;

import com.entrogy.dao.AttendanceDao;

/**
 * @Author 许红松
 * @date 2019/7/4 0004 下午 2:01
 */
public class PersonAddThread extends Thread {

    private String name;
    private int group_id;
    private String phonenumber;
    private String ic_number;
    private String id_number;
    private int gender;
    private String base_image; // address
    private int cover_type;
    private int personType;// 0-学生 1-老师 3-家长和访客

    public PersonAddThread(String name, int group_id, String phonenumber, String ic_number, String id_number,
                           int gender, String base_image, int cover_type, int personType) {
        this.name = name;
        this.group_id = group_id;
        this.phonenumber = phonenumber;
        this.ic_number = ic_number;
        this.id_number = id_number;
        this.gender = gender;
        this.base_image = base_image;
        this.cover_type = cover_type;
        this.personType = personType;
    }

   /* @Override
    public void run() {
        String nowThdId = "";
        if (personType == 0) {
            StudentBean stuBean = null;
            try {
                stuBean = new AttendanceDao().getStudentBeanById(Integer.parseInt(id_number));
            } catch (NumberFormatException | SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            nowThdId = stuBean.getStudent_thdid();
        } else if (personType == 1) {
            TeacherBean teaBean = new TeacherDao().getTeacher(id_number);
            nowThdId = teaBean.getTeacher_thdid();
        } else if (personType == 3) {
            ParentVisitorBean pvBean = null;
            try {
                pvBean = new VisitDao().getParentVisitorBeanById(id_number);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            nowThdId = pvBean.getParent_visitor_thdid();
        }
        THDio thdio = new THDio();
        JSONObject params = new JSONObject();
        JSONObject res = null;
        if (nowThdId == null || nowThdId.equals("")) {
            // 添加
            params.put("name", name);
            params.put("group_id", group_id);
            params.put("phonenumber", phonenumber);
            params.put("ic_number", ic_number);
            params.put("id_number", id_number);
            params.put("gender", gender);
            params.put("base_image", PicUtils.ImageToBase64(base_image));
            params.put("cover_type", cover_type);
            Log.log.info("实义德添加" + personType + "开始" + id_number);
            res = thdio.THD_interface("/personnel/add", params, false);
            Log.log.info("实义德添加" + personType + "结束" + id_number + "结果: " + res.toString());
        } else {
            // 更新照片
            params.put("personnel_id", nowThdId);
            params.put("base_image", PicUtils.ImageToBase64(base_image));
            Log.log.info("实义德更新" + personType + "开始" + id_number);
            res = thdio.THD_interface("/personnel/change_info", params, false);
            Log.log.info("实义德更新" + personType + "结束" + id_number + "结果: " + res.toString());
        }
        // 添加人员信息,post方式
        if (0 == res.getInt("code")) {
            VisitDao vDao = new VisitDao();
            int thdId = res.getJSONObject("data").getInt("personnel_id");
            try {
                if (personType == 3) {
                    if (vDao.updatePVTHDId(id_number, thdId + "")) {
                        Log.log.info(id_number + "数据库更新" + personType + "实义德id为" + thdId);
                    } else {

                    }
                } else if (personType == 1) {
                    if (vDao.updateTeaTHDId(id_number, thdId + "")) {
                        Log.log.info(id_number + "数据库更新" + personType + "实义德id为" + thdId);
                        JSONObject params_json = new JSONObject();
                        params_json.put("personnel_id", thdId);
                        params_json.put("id_number", StrUtils.add0(thdId + ""));
                        JSONObject res1 = thdio.THD_interface("/personnel/change_info", params_json, false);
                        if (0 == res1.getInt("code")) {
                            Log.log.info(id_number + "实义德更新" + personType + "实义德ic_number为" + StrUtils.add0(thdId + "")
                                    + "成功");
                        } else {
                            Log.log.info(id_number + "实义德更新" + personType + "实义德ic_number为" + StrUtils.add0(thdId + "")
                                    + "失败");
                        }
                    } else {

                    }
                } else if (personType == 0) {
                    if (vDao.updateStuTHDId(id_number, thdId + "")) {
                        Log.log.info(id_number + "数据库更新" + personType + "实义德id为" + thdId);
//						KYBIO kybio = new KYBIO();
//						if (kybio.kybMemberSave(thdId + "", id_number, name, base_image)) {
//							Log.log.info("快易帮保存id为" + id_number + "的学生成功,实义德id为" + thdId);
//						} else {
//							Log.log.info("快易帮保存id为" + id_number + "的学生失败,实义德id为" + thdId);
//						}
                    } else {

                    }
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
*/
}
